package day8;

/**
 * @author oldliu
 * @since 1.0
 */
public class Thread6 extends Thread {
    public Thread6(String n) {
        super(n);
    }

    //线程要执行的任务·
    @Override
    public void run() {
        for (int i = 1; i <= 50; i++) {
            System.out.println(getName() + " print :" + i);
        }
    }

    public static void main(String[] args) {
        //至少5个线程（1主+4个子线程）
        System.out.println("主线程开始：");
        Thread6 th = new Thread6("线程" + 1);
        Thread6 th2 = new Thread6("线程" + 2);
        Thread6 th3 = new Thread6("线程" + 3);
        th.start();
        th2.start();
        th3.start();
        //主线程等th和th2执行完，才继续执行
        try {
            th.join();//当前线程（主线程）等th
            th2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("主线程结束！");
    }
}
